package top.jle.wx.proxy.api.tool;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import top.jle.wx.proxy.api.ResponseBack;
import top.jle.wx.proxy.constant.ToolOption;
import top.jle.wx.proxy.facade.ToolFacade;

@RestController
@RequestMapping("/tool")
@Tag(name = "工具API")
public class ToolAPI {

    @Autowired
    private ToolFacade toolFacade;

    @Operation(summary = "生成永久场景二维码 上限10W个")
    @PostMapping("/qr_limit")
    public ResponseBack<ToolOption.QRCodeResponse> createLimitQR(@Parameter(description="appId") @RequestParam String appId,
                                                                 @Parameter(description="secret") @RequestParam String secret,
                                                                 @Parameter(description="自定义场景码 最长64位") @RequestParam String sceneCode){
        ToolOption.QRCodeResponse response = toolFacade.createLimitQRCode(sceneCode);
        return ResponseBack.success(response);
    }

    @Operation(summary = "生成临时场景二维码")
    @PostMapping("/qr")
    public ResponseBack<ToolOption.QRCodeResponse> createQR(@Parameter(description = "有效时间(秒) 上限:"+ToolOption.TEMP_QR_EXPIRE_SECONDS_LIMIT+"秒 (30天) 最低30秒")
                                                                 @RequestParam Integer expireSeconds,
                                                                 @Parameter(description="自定义场景码 最长64位") @RequestParam String sceneCode){
        ToolOption.QRCodeResponse response = toolFacade.createQRCode(sceneCode,expireSeconds);
        return ResponseBack.success(response);
    }

    @Operation(summary = "长连接转短链接")
    @PostMapping("/long2short")
    public ResponseBack<String> long2Short(@Parameter(description="需要转换的URL") @RequestParam String longUrl){
        String shortUrl = toolFacade.shortUrl(longUrl);
        return ResponseBack.success(shortUrl);
    }



}
